package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-01-10
 * Time: 18:17
 */

/**
 * 全局配置类
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {

    @Autowired
    LoginIntercepter loginIntercepter;

    //使拦截器生效
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //不拦截的url集合
        List<String> urlList = new ArrayList<String>(){{
            add("/user/login");
            add("/user/reg");
            add("/css/**");
            add("/js/**");
            add("/img/**");
            add("/**/*.html");
            add("/edition.md/**");
            add("/edition.md/**");
            add("/article/detail");
            add("/article/myinfobyuid");
            add("/article/list");
            add("/article/totalpage");
//            add("/article/**");

        }};

        registry.addInterceptor(loginIntercepter)
                .addPathPatterns("/**")
                .excludePathPatterns(urlList);
    }
}
